import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;


public class DisplayAuthors {
	
	static final String DATABASE_URL = "jdbc:mysql://localhost/books";
	public static void main(String[] args)
	{
		Connection connection = null; //manages connection
		Statement statement = null; //query statement
		ResultSet resultSet = null; //manages results

		try
		{
			connection = DriverManager.getConnection(DATABASE_URL,"root","");
			statement = connection.createStatement();
			resultSet = statement.executeQuery("select * from Authors");
			
			ResultSetMetaData metaData = resultSet.getMetaData();
			int numberOfColumns = metaData.getColumnCount();
			
			System.out.print("Authors table of Database Books: \n");
			System.out.print("--------------------------------\n");
			
			for(int i=1 ; i<=numberOfColumns ; i++)
				System.out.printf("%-8s\t", metaData.getColumnName(i));
			System.out.println("");
			
			while(resultSet.next())
			{
				for(int i=1 ; i<=numberOfColumns; i++)
					System.out.printf("%-8s\t", resultSet.getObject(i));
				System.out.println("");


			}
			
		}
		catch(SQLException e)
		{
			e.printStackTrace();
		}
		finally
		{
			try
			{
				resultSet.close();
				statement.close();
				connection.close();
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}
		
	}
//This is a comment
}
